<?php

namespace App\Modules\LuckDraw\UserTag;

use App\Modules\LuckDraw\Models\DrawLogModel;
use Illuminate\Support\Facades\Redis;

class WorldCupUserTag implements UserTagInterface {
    private $_luckId;
    private $_userId;
    private $_strategyPool;
    private $_luckDrawUserRedisKey;
    public function __construct(int $luckId, int $_userId, object $strategyPool) {
        $this->_luckId = $luckId;
        $this->_userId = $_userId;
        $this->_strategyPool = $strategyPool;
        $this->_luckDrawUserRedisKey = 'LUCKDRAW:WORLDCUP:DRAW:%s:POOL:%s:USERS';
    }

    public function getStrategyPool():?array{
        if (empty($this->_strategyPool)) {
            return [];
        }
        return [$this->_strategyPool->strategy, $this->_strategyPool->pool];
    }

    private function _isPersonal(){
        return true;
    }

    public function getStrategyAllPool():?array{
        if (empty($this->_strategyPool)) {
            return [];
        }
        $data = [];
        $data[] = [$this->_strategyPool->strategy, $this->_strategyPool->pool, [], $this->_strategyPool->strategy];

        return $data;
    }

    //获取所有策略的名字
    public function getAllStrategyAndUserIds(){
        //获取更改过的奖品信息
        $allStrategy = [];

        if(isset($this->_strategyPool->strategy)){
            array_push($allStrategy, $this->_strategyPool->strategy->name);
        }
        $key = sprintf($this->_luckDrawUserRedisKey, $this->_luckId,$this->_strategyPool->pool);
        $userIds = Redis::SMEMBERS($key)??[];

        return [$allStrategy,$userIds];
    }

    public function getUpdatedUserTagByPoolData(array $newPool): ?array {
        $needUpdate = false;
        //返回修改后的数据
        return [$needUpdate, ''];
    }
}
